#include<iostream>
using namespace std;

void DivideString(const char *pInputStr,  char *pOutputStr){  
    char * ch = pOutputStr;  
    while(*pInputStr==' '){  
        pInputStr++;      
    }  
    while(*pInputStr){  
        *ch = * pInputStr;  
        ch ++;  
        pInputStr ++;  
        while(*pInputStr==' '){  
            *ch = ',';  
            if(*(ch-1)!=',')  
                ch++;  
            pInputStr++;  
        }  
    }  
    //*ch = '\0';  
    if(*(ch - 1) != ','){      
        *ch     = ',';                                                  
        *(++ch) = '\0';     
    }      
}

int main()    
{    
        char *pin = "    This is a     demo";
        char pout[100];
        DivideString(pin, pout);
       	printf("%s \n", pin);
        printf("%s \n", pout);
        return 0;    
}    
